package cn.mdmm.base;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.Before;

import com.alibaba.fastjson.JSON;

/**
 * Created by zpdhy on 6/6/17.
 */
public abstract class InterfaceBaseTest {
    private static class APP_1004 {
    	static String appkey = "XCDG9fxIoRFGWEW808a1G9fxIoXSCZ";
        static String secretKey = "erthtudiasdfgdjhjhfjkashsljhasdfdfg";
    }

    protected Map<String, String> paramMap = new HashMap<String, String>();
    protected Map<String, File> fileMap = new HashMap<String, File>();

    /**
     * 封装公共参数
     */
    @Before
    public void beforeTest() {
        paramMap.clear();
        Long timestamp = System.currentTimeMillis();
        paramMap.put("appKey", APP_1004.appkey);
        paramMap.put("format", "json");
        paramMap.put("timestamp", timestamp+"");
        paramMap.put("ver", "1.0");
    }

    public abstract String getUrl();

    /**
     * 发起请求测试接口
     */
    @After
    public void afterTest() {
        String url = getUrl();
        if (url == null || "".equals(url)) {
            url = URLCOMMON.DEVELOP_URL;
        }
        try {
            System.out.println("---入参：" + JSON.toJSONString(paramMap));
            String data = PostClient.doPost(url, paramMap, fileMap, 3000, 15000, null, APP_1004.secretKey);
            System.out.println("---出参：" + data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
